// -*- coding: utf-8 -*-

#include <string>

#include "elisa/elisa.h"
#include "elisa/parser/elisa_parser.h"

using namespace std;
using namespace elisa;


int main(int argc, char *argv[]) 
{
	elisa::init();
	// TODO
	elisa::useBC3();
	ElisaParser parser;
	
	bool res = false;
	if (argc == 1)
		res = parser.parseStream(cin);
	else if (argc == 2)
		res = parser.parseFile(argv[1]);
	if (!res)
		return EXIT_FAILURE;

	Model model(parser.model());
	elisa::IntervalSolver solver(model);

	while (solver.next()) {
		cout << "Solution " << solver.numSolutions() << endl;

		VarMap::const_iterator vit;
		for (vit = parser.variables().begin(); vit != parser.variables().end(); ++vit) {
			cout << '\t' << vit->second->getName() << " in " << *vit->second->getDomain() << endl;
		}
	}

	if (!solver.numSolutions()) 
		cout << "NO SOLUTION" << endl;
	else 
		cout << solver.numSolutions() << " solution(s)" << endl;

#ifdef ELISA_PROFILE
	cout << "split: " << solver.numSplit() << endl;
	cout << "boxes: " << solver.numProcessedBoxes() << endl;
#endif

	elisa::dismiss();

	return EXIT_SUCCESS;
}
